
/**
*	获取地址栏URL的参数
*
*	parameter:	param	[获取参数]
*			
*/
var getQueryString = function(param){
	var reg = new RegExp("(^|&)"+ param +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return unescape(r[2]);
	return null;
}

/**
*	弹出win窗口
*
*	parameter:	option	[配置项]
*			
*/
var openWindow = function(url, option){
	if (!option) option = {};
	var name = option.name || '',
		win_width = option.width || 1200,
		win_height = option.height || screen.height - 100,
		win_top = option.top || 50,
		win_left = option.left || (screen.width-win_width)/2;
	var specs = 'width='+ win_width +';';
		specs += 'height='+ win_height +';';
		specs += 'left='+ win_left +';';
		specs += 'top='+ win_top +';';
	window.open(url);
}

function openNewWindow(url,w,h){
	if(w == undefined || w == "")  w = 1200;//窗口宽
	if(h == undefined || h == "")  h = screen.height - 80;//窗口高
	var ml = (screen.width - w)/2;//左边距离
	var mt = (screen.height - h)/2;//顶部距离
	mt = 0;
	var parm='width='+ w +',height='+ h +',top='+ mt +',left='+ ml +',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no';
	window.open(url,'',parm);
}
/**
*	弹出自定义窗口
*
*	parameter:	option	[配置项]
*			
*/
var winCustomDialog = function(option){
	var url = option.url;
	
	var self = this;
	// 关闭窗口
	self.closeCustomWindow = function(){
		$(".customWindow").fadeOut();
		$(".customWindowMask").fadeOut();
	}
	var maskHtml = '<div class="maskDiv customWindowMask" onclick="self.closeCustomWindow()"></div>';
	var winHtml = '<div class="customWindow customWindowOn">'+
					'<div class="wd-close" onclick="self.closeCustomWindow()">×</div>'+
					'<div class="wd-cont"></div>'+
				'</div>';
	var customWindowMask = $(".customWindowMask");
	if(customWindowMask.length == 0){
		$("body").append(maskHtml);
	}
	var customWindow = $(".customWindow");
	if(customWindow.length == 0){
		$("body").append(winHtml);
		customWindow = $(".customWindow");
	}
	if (url) {
		customWindow.find(".wd-cont").html('<iframe src="" frameborder="0" style="width:100%;height:100%;"></iframe>');
		var frame = customWindow.find(".wd-cont iframe");
		frame.attr("src", '');
	}
	customWindowMask.show();
	customWindow.show();
	setTimeout(function(){
		customWindow.find(".wd-close").show();
		if (url) frame.attr("src", url);
	},500);
}

/**
*	获取浏览器类型及版本
*
*/
var getBrowserType = function () {
    var userAgent = window.navigator.userAgent;
    var browserType, browserVersion;
    // ie
    if (userAgent.indexOf("MSIE") >= 0) {
        var browser = navigator.appName;
        var b_version = navigator.appVersion;
        var version = b_version.split(";");
        var trim_Version = version[1].replace(/[ ]/g, "");
        var number = "";
        for (i = 0; i < trim_Version.length; i++) {
            if ("0123456789".indexOf(trim_Version.substr(i, 1)) > -1)
                number += trim_Version.substr(i, 1);
        }
        if (number < "8.0"){
            if (trim_Version == "MSIE6.0" ) {
                var divName = document.getElementById("tixing");
                var text = "您的浏览器版本过低(当前浏览器版本为IE6)，系统建议您采用高版本的主流浏览器!";
                divName.innerHTML = text;
            }
            else if (trim_Version == "MSIE7.0" ) {
	            var divName = document.getElementById("tixing");
	            var text = "您的浏览器版本过低(当前浏览器版本为IE7)，系统建议您采用高版本的主流浏览器!";
	            divName.innerHTML=text;
            }
            else if (trim_Version == "MSIE5.5" ) {
	            var divName = document.getElementById("tixing");
	            var text = "您的浏览器版本过低(当前浏览器版本为IE5)，系统建议您采用高版本的主流浏览器!";
	            divName.innerHTML=text;
            }else{
                document.getElementById('tixing').style.display='none';
            }
        }else{
            document.getElementById('tixing').style.display='none';
        }
		browserType = "IE";
		browserVersion = number;
    }
    // firefox
    else if (userAgent.indexOf("Firefox") >= 0) browserType = "Firefox";
    // Chrome
    else if (userAgent.indexOf("Chrome") >= 0) browserType = "Chrome";
    // Opera
    else if (userAgent.indexOf("Opera") >= 0) browserType = "Opera";
    // Safari
    else if (userAgent.indexOf("Safari") >= 0) browserType = "Safari";
    
    return { type: browserType, version: browserVersion };
}

/**
*	自定义tabs
*
*	parameter:	option	[配置项]
*			
*/
var customPanelTabs = function(obj, callback){
	var tab = $(obj).find(".tabs .tab"),
		panelBody = $(obj).find(".panel-body");
	tab.on('click', function(){
		$(this).addClass("active").siblings().removeClass("active");
		var index = tab.index($(this));
		panelBody.hide();
		panelBody.eq(index).show();
		return callback(index);
	});
	tab.first().click();
}